package acm;

import org.junit.Test;

import java.io.InputStreamReader;
import java.util.*;

public class Test1513 {
    public static void main(String[] args) {
        Scanner sc= new Scanner(new InputStreamReader( System.in));
        int n=0;
        List<Integer> list=new ArrayList<Integer>();
        while ((n=sc.nextInt())!=0){
            list.add(n);
        }
        for (Integer integer : list) {
            System.out.println(digitOneInNumber(integer));
        }
    }

    /**
     * 给定一个整数 num，计算所有小于等于 num 的非负整数中数字 1 出现的个数。
     */
    @Test
    public void test(){
        System.out.println(digitOneInNumber(1410065408));
    }

    public static int digitOneInNumber(int num) {
        long height,low,cur,base=1;
        int res=0;
        while (base<=num){
            cur=(num/base)%10;
            low=num%base;
            height=num/base/10;
            if (cur>1){
                res+=(height+1)*base;
            }else if (cur==1){
                res+=height*base+low+1;
            }else {
                res+=height*base;
            }
            base*=10;
        }
        return res;
    }
}